﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public partial class Fmchange : Form
    {
        public string StaID;
        public string status;
        public StaffMassage myParentErm;
        public Fmchange()
        {
            InitializeComponent();
        }
        BLL.Staff bLKM = new BLL.Staff();
        Model.Staff mLKM = new Model.Staff();

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void Fmchange_Load(object sender, EventArgs e)
        {
            btnSubmit.Text = status;
            if (status == "修改") 
            {
                DataTable dt = bLKM.select("StaID='"+StaID +"'");
                textBox1.Text = dt.Rows[0]["StaID"].ToString();
                textBox2.Text = dt.Rows[0]["StaName"].ToString();
                textBox3.Text = dt.Rows[0]["StaNumber"].ToString();
            }

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            mLKM.StaID = textBox1.Text;
            mLKM.StaName = textBox2.Text;
            mLKM.StaNumber = textBox3.Text;
            bool result = false;
            switch (status)
            {
                case "修改":
                    mLKM.StaID = StaID;
                    result = bLKM.update(mLKM,StaID);
                    break;
                case "添加":
                    result = bLKM.insert (mLKM);
                    break;
            }
            if (result)
            {
                myParentErm.bindGrudView();
                MessageBox.Show(status + "成功！");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
            else
                MessageBox.Show(status + "失败！");
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
    }
}
